﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccessLayer;
using System.Configuration;
using System.IO;

namespace WebApplication
{
    public partial class NonMemberShip : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Attributes.Add("OnClick", "return ValidateCompanyMaster('" + txtFirstName.ClientID + "','" + txtLastName.ClientID + "', '" + txtContactNumber1.ClientID + "', '" + txtEmailID.ClientID + "', '" + txtConfirmEmailID.ClientID + "', '" + txtPassword.ClientID + "', '" + txtConfirmaPassword.ClientID + "','" + ddlCountry.ClientID + "','" + ddlCity.ClientID + "', '" + hdnAlertCounter.ClientID + "');");

            CountryService service = new CountryService();
            List<string> country = service.GetCountry();
            ddlCountry.DataSource = country;
            ddlCountry.DataBind();
            ddlCountry.Items.Insert(0, "Country");
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> > <a href='sign-in.aspx'>Sign In / Sign Up</a> > <span>New Registration</span>";
        
        }

        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string FirstName = txtFirstName.Text.Trim();
            string LastName = txtLastName.Text.Trim();
            string Contact1 = txtContactNumber1.Text.Trim();
            string Contact2 = txtContactNumber2.Text.Trim();
            string EmailID = txtConfirmEmailID.Text.Trim();
            string Password = txtConfirmaPassword.Text;
            bool isNewlatter = chkNewsLatter.Checked;
            string Country = Request.Form.GetValues("ctl00$MainContent$ddlCountry")[0];
            int Result = clsUser.NonMemberShipUserRegistration(FirstName, LastName,Country, Contact1, Contact2, EmailID, Password,isNewlatter);
            if (Result>0)
            {
                string MailContent = File.ReadAllText(Server.MapPath("signup-email.html"));
                MailContent = MailContent.Replace("####", "http://realestate-contracting.com" + "/NonMemberActivation.aspx?ID=" + Result);
                Utility.sendMail(EmailID, "Please activate your account", MailContent);
                Utility.sendMail(ConfigurationManager.AppSettings["AdminEmail"].ToString(),"Non Member User Registration", "A new "+FirstName +" "+LastName+" has current registered in RealStudio");
                Response.Redirect("Thanks.aspx");
            }
            if (Result == -2)
            {
                lblMessage.Text = "You are already existing user. Please click to forget password for retriving your password.";
                Response.Redirect("Thanks.aspx");
            }

        }

    }
}